package com.john.bms.controller.system;

import com.github.pagehelper.PageInfo;
import com.john.bms.model.result.RequestResult;
import com.john.bms.model.system.UserVo;
import com.john.bms.model.system.dictionaries.DictionariesPage;
import com.john.bms.model.system.dictionaries.SysDictionarie;
import com.john.bms.service.system.DictionariesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.john.bms.utils.CollectionUtils.map;

/**
 * @Author:张家小帅哥
 * @Date:2020/11/30 10:58
 * @Version:1.0
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/dictionaries")
public class DictionariesController {

    @Resource
    private DictionariesService dictionariesService;

    @RequiresPermissions("dictionaries:view")
    @PostMapping("/dictionariesPageList")
    public RequestResult dictionariesPageList(DictionariesPage page) {
        PageInfo<SysDictionarie> pageList = dictionariesService.getPageList(page);
        return RequestResult.of(map(pageList, "data"));
    }

    @PostMapping("/dictionariesAdd")
    public RequestResult dictionariesAdd(SysDictionarie de) {
        boolean result = dictionariesService.addDictionaries(de);
        return RequestResult.of(map(result, "data"));
    }

    @GetMapping("/dictionariesInfo")
    public RequestResult dictionariesInfo(String params) {
        SysDictionarie dictionariesInfo = dictionariesService.getDictionariesInfo(params);
        return RequestResult.of(map(dictionariesInfo, "data"));
    }

    @PostMapping("/dictionariesUpdate")
    public RequestResult dictionariesUpdate(SysDictionarie de) {
        boolean result = dictionariesService.updateDictionaries(de);
        return RequestResult.of(map(result, "data"));
    }


}
